package com.xh.bussiness.tiku.controller;

import com.xh.bussiness.tiku.bean.dto.QuestionDto;
import com.xh.bussiness.tiku.bean.request.BookVersionRequest;
import com.xh.bussiness.tiku.bean.request.QuestionCollectRequest;
import com.xh.bussiness.tiku.bean.request.QuestionQueryRequest;
import com.xh.bussiness.tiku.bean.request.QuestionSaveRequest;
import com.xh.bussiness.tiku.model.QuestionCollect;
import com.xh.bussiness.tiku.service.IBookVersionService;
import com.xh.bussiness.tiku.service.IQuestionCollectService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author tw
 * @since 2019/9/11
 */
@Api(tags="试题收藏接口")
@RestController
@RequestMapping("/tiku/questionCollect")
public class QuestionCollectController extends BaseController {

    @Autowired
    private IQuestionCollectService questionCollectService;

    @PostMapping("/add")
    @ApiOperation(value = "试题收藏", notes = "试题收藏")
    @Transactional
    public AjaxResult add(@RequestBody QuestionCollectRequest bean) {
        Integer i = questionCollectService.addQuestionCollect(bean);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,bean);
    }

    @PostMapping("/queryPage")
    @ApiOperation(value = "试题收藏查询", notes = "试题收藏查询")
    public AjaxResult queryPage(XhPage page,QuestionCollectRequest bean) throws Exception {

        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,questionCollectService.queryPage(page,bean));
    }

    @PostMapping("/query")
    @ApiOperation(value = "试题收藏查询", notes = "试题收藏查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bean", value = "试题收藏信息", required = true, dataType = "QuestionCollectRequest"),
    })
    public AjaxResult query(QuestionCollectRequest bean) {
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, "", questionCollectService.queryQuestionCollect(bean));
    }



    @PostMapping("/delete")
    @ApiOperation(value = "试题收藏删除", notes = "试题收藏删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "试题收藏ID", required = true, dataType = "String"),
    })
    @Transactional
    public AjaxResult delete(String id) {
        String msg = questionCollectService.deleteQuestionCollect(id);
        return new AjaxResult(msg == null, msg);
    }

    @PostMapping("/cancelCollect")
    @ApiOperation(value = "取消试题收藏", notes = "取消试题收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bean", value = "试题收藏信息", required = true, dataType = "QuestionCollectRequest"),
    })
    @Transactional
    public AjaxResult cancelCollect(QuestionCollectRequest bean) {
        String msg = questionCollectService.cancelCollect(bean);
        return new AjaxResult(msg == null, msg);
    }
}
